<template>
	<view class="p60">
		<view class="title">
			完善信息
		</view>

		<view class="input-phone">
			<input  v-model="formData.name" class="uni-input"  :placeholder="namePlaceHolder" />
		</view>

		<view class="line" />

		<view class="input-phone">
			<input  v-model="formData.work" class="uni-input"  :placeholder="workPlaceHolder" />
		</view>

		<view class="line" />

		<view class="input-phone">
			<input v-model="formData.job" class="uni-input" :placeholder="jobPlaceHolder" />
		</view>

		<view class="line" />

		<view class="btn-submit" @click="submit">
			提交
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';

	export default {
		data() {
			return {
				formData: {
					name: null,
					work: null,
					job: null
				},
			}
		},
		onLoad() {
			if(this.userInfo !== null){
				this.formData.name = this.userInfo.name;
				this.formData.work = this.userInfo.company;
				this.formData.job = this.userInfo.job;
			}
		},
		computed: {
			...mapState('userStore', ['hasLogin', 'userInfo']),
			jobPlaceHolder() {
				return '请输入您的职务';
			},
			workPlaceHolder() {
				return  '请输入您的工作单位';
			},
			namePlaceHolder() {
				return  '请输入您的姓名';
			}
		},
		methods: {
			verifyFormData(cb) {

				if (this.formData.name === null) {
					uni.showToast({
						title: '请输入姓名',
						duration: 2000,
						icon: 'none'
					})
					return;
				}

				if (this.formData.work === null) {
					uni.showToast({
						title: '请输入工作单位',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				if (this.formData.job === null) {
					uni.showToast({
						title: '请输入职务',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				cb && cb();

			},
			submit() {
				this.verifyFormData(() => {
					this.$request.get({
						url: 'updateUser',
						data: this.formData,
						loadingTip: '正在处理...'
					}).then(res => {
						uni.showToast({
							title: '信息更新成功！',
							duration: 2000,
							icon: 'none'
						})
						setTimeout(() => {
							uni.navigateBack({

							});
						}, 1000);
					}, res => {});
				});

			},
		}
	}
</script>

<style>
	.p60 {
		padding: 0 60upx;
	}


	.input-phone {
		margin-top: 100upx;
	}

	.line {
		width: 100%;
		height: 2upx;
		background: rgba(239, 239, 239, 1);
		box-shadow: 0px 6upx 24upx 0upx rgba(56, 73, 184, 0.04);
		border-radius: 16upx;
		margin: 20upx auto;
	}

	.btn-submit {
		margin-top: 180upx;
		width: 620upx;
		height: 98upx;
		background: linear-gradient(183deg, rgba(11, 200, 253, 1) 0%, rgba(4, 151, 250, 1) 100%);
		border-radius: 50upx;

		color: #FFFFFF;
		font-size: 36upx;
		line-height: 98upx;
		text-align: center;
	}

	.uni-input {
		font-size: 32upx;
		color: #999999;
	}

	.title {
		font-size: 48upx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(72, 82, 107, 1);
		margin-top: 120upx;
	}
</style>